import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Form';
import { useI18n } from '/@/hooks/web/useI18n';
import { getPartFeature, getCodeList } from '/@/api/demo/system';

const { t } = useI18n();

export function getPartSettingColumns(): BasicColumn[] {
  return [
    {
      title: t('routes.demo.partSetting.typeId'),
      dataIndex: 'partName',
      width: 150,
      fixed: 'left',
    },
    {
      title: t('routes.demo.partSetting.firstFeature'),
      dataIndex: 'firstFeature',
      align: 'center',
      width: 120,
    },
    {
      title: t('routes.demo.partSetting.secondFeature'),
      dataIndex: 'secondFeature',
      width: 120,
    },
    {
      title: t('routes.demo.partSetting.matchPriority'),
      dataIndex: 'verdictpriority',
      width: 120,
    },
    {
      title: t('routes.demo.partSetting.defaultType'),
      dataIndex: 'defaultag',
      width: 120,
      slots: { customRender: 'defaultag' },
    },
  ];
}

export function getSetConfig(): FormSchema[] {
  return [
    {
      field: 'firstFeature',
      component: 'ApiSelect',
      label: t('routes.demo.partSetting.firstFeature'),
      componentProps: {
        placeholder: t('routes.demo.partSetting.firstFeaturePlaceholder'),
        api: getPartFeature,
        resultField: 'partList',
        labelField: 'value',
        valueField: 'label',
      },
    },
    {
      field: 'secondFeature',
      component: 'ApiSelect',
      label: t('routes.demo.partSetting.secondFeature'),
      componentProps: {
        placeholder: t('routes.demo.partSetting.secondFeaturePlaceholder'),
        api: getPartFeature,
        resultField: 'partList',
        labelField: 'value',
        valueField: 'label',
      },
    },
  ];
}

export function getClassColumns(): BasicColumn[] {
  return [
    {
      title: t('routes.demo.partSetting.propertyId'),
      dataIndex: 'prop',
      width: 150,
      fixed: 'left',
    },
    {
      title: t('routes.demo.partSetting.propertyName'),
      dataIndex: 'name',
      align: 'center',
      width: 120,
    },
    {
      title: t('routes.demo.partSetting.dataType'),
      dataIndex: 'dataType',
      width: 120,
    },
    {
      title: t('routes.demo.partSetting.length'),
      dataIndex: 'length',
      width: 100,
    },
    {
      title: t('routes.demo.partSetting.control'),
      dataIndex: 'attr',
      width: 120,
      slots: { customRender: 'attr' },
    },
    {
      title: t('routes.demo.partSetting.order'),
      dataIndex: 'dispIndex',
      width: 100,
    },
    {
      title: t('routes.demo.partSetting.optionalValue'),
      dataIndex: 'defaultValue',
      width: 120,
    },
    {
      title: t('routes.demo.partSetting.allowEmpty'),
      dataIndex: 'pdmnull',
      width: 100,
      slots: { customRender: 'pdmnull' },
    },
    {
      title: t('routes.demo.partSetting.isSensitiveProperty'),
      dataIndex: 'isOnly',
      width: 100,
      slots: { customRender: 'isOnly' },
    },
  ];
}

export function getClassPropForm(isUpdate, canChange): FormSchema[] {
  return [
    {
      field: 'prop',
      component: 'Input',
      label: t('routes.demo.partSetting.propertyId'),
      required: true,
      componentProps: {
        placeholder: t('routes.demo.partSetting.propertyIdPlaceholder'),
      },
      dynamicDisabled: () => {
        return canChange.value === '0' || canChange.value === '1';
      },
    },
    {
      field: 'name',
      component: 'Input',
      label: t('routes.demo.partSetting.propertyName'),
      required: true,
      componentProps: {
        placeholder: t('routes.demo.partSetting.propertyNamePlaceholder'),
      },
      dynamicDisabled: () => {
        return canChange.value === '0';
      },
    },
    {
      field: 'dataType',
      component: 'Select',
      label: t('routes.demo.partSetting.dataType'),
      required: true,
      componentProps: {
        placeholder: t('routes.demo.partSetting.dataTypePlaceholder'),
        options: [
          {
            label: t('routes.demo.FigureDocSettings.varchar'),
            value: 'varchar',
          },
          {
            label: t('routes.demo.FigureDocSettings.datetime'),
            value: 'datetime',
          },
          {
            label: t('routes.demo.FigureDocSettings.int'),
            value: 'int',
          },
          {
            label: t('routes.demo.FigureDocSettings.float'),
            value: 'float',
          },
          {
            label: t('routes.demo.FigureDocSettings.boolean'),
            value: 'bool',
          },
          // {
          //   label: t('routes.demo.FigureDocSettings.joint'),
          //   value: 'joint',
          // },
          // {
          //   label: t('routes.demo.FigureDocSettings.dataext'),
          //   value: 'dataext',
          // },
        ],
      },
      dynamicDisabled: () => {
        return canChange.value === '0' || canChange.value === '1';
      },
    },
    {
      field: 'length',
      component: 'Input',
      label: t('routes.demo.partSetting.length'),
      required: true,
      defaultValue: '64',
      componentProps: {
        placeholder: t('routes.demo.partSetting.lengthPlaceholder'),
      },
      dynamicDisabled: () => {
        return canChange.value === '0';
      },
    },
    {
      field: 'attr',
      component: 'Select',
      label: t('routes.demo.partSetting.control'),
      required: true,
      componentProps: {
        placeholder: t('routes.demo.partSetting.controlPlaceholder'),
        options: [
          {
            label: t('routes.demo.FigureDocSettings.text'),
            value: '256',
          },
          {
            label: t('routes.demo.FigureDocSettings.select'),
            value: '128',
          },
          {
            label: t('routes.demo.FigureDocSettings.calendar'),
            value: '8448',
          },
          {
            label: t('routes.demo.FigureDocSettings.resource'),
            value: '1024',
          },
          {
            label: t('routes.demo.FigureDocSettings.resourceMultiple'),
            value: '768',
          },
        ],
      },
      dynamicDisabled: () => {
        return canChange.value === '0';
      },
    },
    {
      field: 'dispIndex',
      component: 'Input',
      label: t('routes.demo.partSetting.order'),
      required: true,
      componentProps: {
        placeholder: t('routes.demo.partSetting.orderPlaceholder'),
      },
      dynamicDisabled: () => {
        return !isUpdate.value;
      },
    },
    {
      field: 'defaultValue',
      component: 'InputTextArea',
      helpMessage: t('routes.demo.partSetting.optionalValueSplit'),
      label: t('routes.demo.partSetting.optionalValue'),
      defaultValue: '',
      componentProps: {
        placeholder: t('routes.demo.partSetting.optionalValuePlaceholder'),
      },
      dynamicDisabled: () => {
        return canChange.value === '0';
      },
    },
    {
      field: 'pdmnull',
      component: 'Checkbox',
      defaultValue: true,
      label: t('routes.demo.partSetting.allowEmpty'),
      dynamicDisabled: () => {
        return canChange.value === '0' || canChange.value === '1';
      },
    },
    {
      field: 'readOnly',
      component: 'Checkbox',
      defaultValue: false,
      label: t('routes.demo.partSetting.readOnly'),
      dynamicDisabled: () => {
        return canChange.value === '0';
      },
    },
    {
      field: 'isOnly',
      component: 'Checkbox',
      defaultValue: false,
      label: t('routes.demo.partSetting.isSensitiveProperty'),
      dynamicDisabled: () => {
        return canChange.value === '0';
      },
    },
  ];
}

export function getPartClassPropForm(isUpdate, canChange): FormSchema[] {
  return [
    {
      field: 'prop',
      component: 'Input',
      label: t('routes.demo.partSetting.propertyId'),
      required: true,
      componentProps: {
        placeholder: t('routes.demo.partSetting.propertyIdPlaceholder'),
      },
      dynamicDisabled: () => {
        return canChange.value === '0' || canChange.value === '1';
      },
      rules: [
        {
          required: true,
          message: t('routes.demo.partSetting.propRule'),
          pattern: /^[a-zA-Z]/,
          trigger: 'blur',
        },
      ],
    },
    {
      field: 'name',
      component: 'Input',
      label: t('routes.demo.partSetting.propertyName'),
      required: true,
      componentProps: {
        placeholder: t('routes.demo.partSetting.propertyNamePlaceholder'),
      },
      dynamicDisabled: () => {
        return canChange.value === '0';
      },
    },
    {
      field: 'dataType',
      component: 'Select',
      label: t('routes.demo.partSetting.dataType'),
      required: true,
      componentProps: {
        placeholder: t('routes.demo.partSetting.dataTypePlaceholder'),
        options: [
          {
            label: t('routes.demo.FigureDocSettings.varchar'),
            value: 'varchar',
          },
          {
            label: t('routes.demo.FigureDocSettings.datetime'),
            value: 'datetime',
          },
          {
            label: t('routes.demo.FigureDocSettings.int'),
            value: 'int',
          },
          {
            label: t('routes.demo.FigureDocSettings.float'),
            value: 'float',
          },
          {
            label: t('routes.demo.FigureDocSettings.boolean'),
            value: 'bool',
          },
          // {
          //   label: t('routes.demo.FigureDocSettings.joint'),
          //   value: 'joint',
          // },
          // {
          //   label: t('routes.demo.FigureDocSettings.dataext'),
          //   value: 'dataext',
          // },
        ],
      },
      dynamicDisabled: () => {
        return canChange.value === '0' || canChange.value === '1';
      },
    },
    {
      field: 'length',
      component: 'Input',
      label: t('routes.demo.partSetting.length'),
      required: true,
      componentProps: {
        placeholder: t('routes.demo.partSetting.lengthPlaceholder'),
      },
      dynamicDisabled: () => {
        return canChange.value === '0';
      },
    },
    {
      field: 'attr',
      component: 'Select',
      label: t('routes.demo.partSetting.control'),
      required: true,
      componentProps: {
        placeholder: t('routes.demo.partSetting.controlPlaceholder'),
        options: [
          {
            label: t('routes.demo.FigureDocSettings.text'),
            value: '256',
          },
          {
            label: t('routes.demo.FigureDocSettings.select'),
            value: '384',
          },
          {
            label: t('routes.demo.FigureDocSettings.calendar'),
            value: '8448',
          },
          {
            label: t('routes.demo.FigureDocSettings.resource'),
            value: '1080',
          },
          {
            label: t('routes.demo.FigureDocSettings.resourceMultiple'),
            value: '768',
          },
        ],
      },
      dynamicDisabled: () => {
        return canChange.value === '0';
      },
    },
    {
      field: 'dispIndex',
      component: 'Input',
      label: t('routes.demo.partSetting.order'),
      required: true,
      componentProps: {
        placeholder: t('routes.demo.partSetting.orderPlaceholder'),
      },
      dynamicDisabled: () => {
        return !isUpdate.value;
      },
    },
    {
      field: 'defaultValue',
      component: 'InputTextArea',
      helpMessage: t('routes.demo.partSetting.optionalValueSplit'),
      label: t('routes.demo.partSetting.optionalValue'),
      defaultValue: '',
      componentProps: {
        placeholder: t('routes.demo.partSetting.optionalValuePlaceholder'),
      },
      dynamicDisabled: () => {
        return canChange.value === '0';
      },
    },
    {
      field: 'pdmnull',
      component: 'Checkbox',
      defaultValue: true,
      label: t('routes.demo.partSetting.allowEmpty'),
      dynamicDisabled: () => {
        return canChange.value === '0' || canChange.value === '1';
      },
    },
    {
      field: 'readOnly',
      component: 'Checkbox',
      defaultValue: false,
      label: t('routes.demo.partSetting.readOnly'),
      dynamicDisabled: () => {
        return canChange.value === '0';
      },
    },
    {
      field: 'isOnly',
      component: 'Checkbox',
      defaultValue: false,
      ifShow: false,
      label: t('routes.demo.partSetting.isSensitiveProperty'),
      dynamicDisabled: () => {
        return canChange.value === '0';
      },
    },
  ];
}

export function getPartCategoryForm(isUpdate): FormSchema[] {
  return [
    {
      field: 'partId',
      component: 'Input',
      label: t('routes.demo.partSetting.typeId'),
      required: true,
      componentProps: {
        placeholder: t('routes.demo.partSetting.typeIdPlaceholder'),
      },
      dynamicDisabled: () => {
        return isUpdate.value;
      },
    },
    {
      field: 'counterID',
      component: 'ApiSelect',
      label: t('routes.demo.partSetting.codingSystemAssociation'),
      componentProps: {
        placeholder: t('routes.demo.partSetting.codingSystemAssociationPlaceholder'),
        api: getCodeList,
        labelField: 'remark',
        valueField: 'counterID',
      },
    },
    {
      field: 'firstFeature',
      component: 'Input',
      label: t('routes.demo.partSetting.firstFeature'),
      helpMessage: t('routes.demo.partSetting.materialStatus'),
      componentProps: {
        placeholder: t('routes.demo.partSetting.firstFeaturePlaceholder'),
        // api: getPartFeature,
        // resultField: 'partList',
        // labelField: 'value',
        // valueField: 'label',
      },
    },
    {
      field: 'secondFeature',
      component: 'Input',
      label: t('routes.demo.partSetting.secondFeature'),
      helpMessage: t('routes.demo.partSetting.remark'),
      componentProps: {
        placeholder: t('routes.demo.partSetting.secondFeaturePlaceholder'),
        // api: getPartFeature,
        // resultField: 'partList',
        // labelField: 'value',
        // valueField: 'label',
      },
    },
    {
      field: 'disIndex',
      component: 'Input',
      label: t('routes.demo.partSetting.matchPriority'),
      required: true,
      componentProps: {
        placeholder: t('routes.demo.partSetting.matchPriorityPlaceholder'),
      },
      dynamicDisabled: () => {
        return isUpdate.value;
      },
    },
    {
      field: 'isDefault',
      component: 'Checkbox',
      label: t('routes.demo.partSetting.defaultType'),
    },
  ];
}

export function getPartClassPropColumns(): BasicColumn[] {
  return [
    {
      title: t('routes.demo.partSetting.code'),
      dataIndex: 'prop',
      width: 150,
      fixed: 'left',
    },
    {
      title: t('routes.demo.partSetting.name'),
      dataIndex: 'name',
      align: 'center',
      width: 120,
    },
    {
      title: t('routes.demo.partSetting.selectProperty'),
      dataIndex: 'isSelect',
      width: 120,
      slots: { customRender: 'isSelect' },
    },
    {
      title: t('routes.demo.partSetting.selectSensitiveProperty'),
      dataIndex: 'isOnly',
      width: 120,
      slots: { customRender: 'isOnly' },
    },
    {
      title: t('routes.demo.partSetting.isSystemCategoryProperty'),
      dataIndex: 'isSystem',
      width: 120,
      slots: { customRender: 'isSystem' },
    },
  ];
}
